<template>
  <div class="talk">

    <ul>
      <li v-for="talk in loveTalkList" :key="talk.id">
        {{ talk.content }}
      </li>
    </ul>

    <button @click="getTalk">获取一句话</button>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive, toRef } from "vue"
import axios from "axios";
import { useLoveTolkStore } from '@/store/loveTalk'

const {loveTalkList} = useLoveTolkStore()
console.log(loveTalkList);


async function getTalk() {
  let { data: { id }, data: { hitokoto: content } } = await axios.get('https://v1.hitokoto.cn/')
  loveTalkList.unshift({ id, content })

  //   // 这样可以直接根据返回对象解构出想要内容  data:{hitokoto:content} 这是重命名成项目需要的
  // let {data:{id:id},data:{content}} = await axios.get('https://api.uomg.com/api/rand.qinghua')
  // talkList.unshift({id , content})
}

</script>

<style lang="scss" scoped>
.talk {
  background-color: pink;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}
</style>
